import jsonschema

j_schema = {
    "type": "object",
    "properties": {
        "success": {"const": True},
        "code": {"type": "integer"},
        "message": {"pattern": "成功"},
        "mobile": {"pattern": "^[1-9]{11}$"},
        "data": {
            "type": "object",
            "properties": {
                "name": {"pattern": "^[a-z]"},
                "age": {"const": 20}
            }
        }
    },
    "required": ["success", "code", "message", "mobile", "data"]
}

data = {
    "success": True,
    "code": 10000,
    "message": "登录成功！",
    "mobile": "13918187766",
    "data": {
        "name": "lily",
        "age": 20
    }
}

res = jsonschema.validate(schema=j_schema, instance=data)
print('校验结果====', res)
